using System.Configuration;

namespace Lync.Widget.Library.Configuration
{
    public class LanguageResourceElementCollection : ConfigurationElementCollection
    {
        protected override ConfigurationElement CreateNewElement()
        {
            return new LanguageResourceElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            var key = ((LanguageResourceElement) element).Name + "_" + ((LanguageResourceElement) element).Key;
            return key;
        }

        public override ConfigurationElementCollectionType CollectionType
        {
            get { return ConfigurationElementCollectionType.BasicMap; }
        }

        protected override string ElementName
        {
            get { return "Resource"; }
        }

        public LanguageResourceElement this[int index]
        {
            get { return (LanguageResourceElement)BaseGet(index); }
            set
            {
                if (BaseGet(index) != null)
                {
                    BaseRemoveAt(index);
                }
                BaseAdd(index, value);
            }
        }

        new public LanguageResourceElement this[string key]
        {
            get { return (LanguageResourceElement)BaseGet(key); }
        }

        public bool ContainsKey(string key)
        {
            bool result = false;
            object[] keys = BaseGetAllKeys();
            foreach (object obj in keys)
            {
                if ((string)obj == key)
                {
                    result = true;
                    break;
                }
            }
            return result;
        }
    }
}